package com.carter.springframework.beans.factory.support;

import com.carter.springframework.beans.factory.config.ConstructorArgumentValues;
import com.sun.istack.internal.Nullable;

public final class BeanDefinitionBuilder {
    private final AbstractBeanDefinition beanDefinition;

    private int constructorArgIndex;

    private BeanDefinitionBuilder(AbstractBeanDefinition beanDefinition) {
        this.beanDefinition = beanDefinition;
    }

    public static BeanDefinitionBuilder genericBeanDefinition(Class<?> beanClass) {
        BeanDefinitionBuilder builder = new BeanDefinitionBuilder(new GenericBeanDefinition());
        builder.beanDefinition.setBeanClass(beanClass);
        return builder;
    }

    public BeanDefinitionBuilder addConstructorArgValue(@Nullable Object value) {
        this.beanDefinition.getConstructorArgumentValues().addIndexedArgumentValue(
                this.constructorArgIndex++, value);
        return this;
    }

    public AbstractBeanDefinition getBeanDefinition(){
        //this.beanDefinition.validate();
        return this.beanDefinition;
    }

}
